package com.bouvet.wave;

import com.google.wave.api.*;


import java.io.IOException;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.logging.Logger;

public class TagcloudWaveServlet extends AbstractRobotServlet {
	private static final Logger log = Logger.getLogger(TagcloudWaveServlet.class
			.getName());

	Hashtable hashWavesChatBot;
	
	@Override
	public void processEvents(RobotMessageBundle bundle) {
		Wavelet wavelet = bundle.getWavelet();

		if (bundle.wasSelfAdded()) {
			Blip blip = wavelet.appendBlip();
			TextView textView = blip.getDocument();
			Gadget gadgetTagCloud = new Gadget("http://tagcloud-wave.appspot.com/gadget_tagcloud.xml");

			gadgetTagCloud.setField("TagsJSON", getTagCloudJSON(wavelet));
			textView.appendElement(gadgetTagCloud);
			textView.append("Gadget added");
		}

		for (Event e : bundle.getEvents()) {
			//log.info("Got event " + e);
			if (e.getType() == EventType.BLIP_SUBMITTED ){
				Blip orgBlip = e.getBlip();
				String strResponse= "dummy";
				if(strResponse!= null && !strResponse.trim().equals("")){
					Blip blip = orgBlip.createChild();
					TextView textView = blip.getDocument();
					textView.append(strResponse);
				}
				
			}
		}
	}
	
	public String getTagCloudJSON(Wavelet wavelet){
		//String jsonTags = "[{\"name\":\"Bouvet\",\"count\":\"15\"},{\"name\":\"Dagfinn\",\"count\":\"5\"},{\"name\":\"Wave\",\"count\":\"5\"},{\"name\":\"SAP\",\"count\":\"4\"},{\"name\":\"Awesome\",\"count\":\"2\"},{\"name\":\"Tagcloud\",\"count\":\"10\"}]";
		String jsonTags = "[{'name':'Bouvet','count':'15'},{'name':'Dagfinn','count':'5'},{'name':'Wave','count':'5'},{'name':'SAP','count':'4'},{'name':'Awesome','count':'2'},{'name':'Tagcloud','count':'10'}]";
		
		return jsonTags;
	}

}